//
//  DHHomeActivityCell.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/4/13.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHHomeActivityCell.h"
#import "DHS2_ActivityDetailController.h"

@interface DHHomeActivityCell()<UIScrollViewDelegate>

@property (strong, nonatomic) NSArray *modelArr; //数据

@end

@implementation DHHomeActivityCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.scrollView.delegate = self;
}

- (void)updateCellWithArray:(NSArray *)arr{
    self.modelArr = arr;
    self.scrollView.contentSize = CGSizeMake(arr.count * kScreenWidth, self.scrollView.height);
    
    for (int i = 0; i < arr.count; i++) {
        NSDictionary *model = arr[i];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * kScreenWidth, 0, kScreenWidth, self.scrollView.height)];
        [imageView dh_setImageURLString:[model objectForKey:@"cover"]];
        if (i == 0) {
            self.titleLabel.text = [model objectForKey:@"title"];
        }
        imageView.tag = i;
        imageView.userInteractionEnabled = YES;
        [imageView bk_whenTapped:^{
            DHS2_ActivityDetailController *adVC = [[DHS2_ActivityDetailController alloc] initWithDic:self.modelArr[imageView.tag]];
            adVC.hidesBottomBarWhenPushed = YES;
            [self.viewController.navigationController pushViewController:adVC animated:YES];
        }];
        [self.scrollView addSubview:imageView];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSInteger index = scrollView.contentOffset.x / self.scrollView.width;
    NSDictionary *model = self.modelArr[index];
    self.titleLabel.text = [model objectForKey:@"title"];
}

@end
